package com.ruoyi.web.controller.module.event;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.event.EventType;
import com.ruoyi.system.service.module.event.IEventTypeService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 事件计划类型Controller
 *
 * @author ruoyi
 * @date 2023-12-25
 */
@Validated
@Api(value = "事件计划类型控制器", tags = {"事件计划类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/event/type")
public class EventTypeController extends BaseController {

    private final IEventTypeService eventTypeService;

    /**
     * 查询事件计划类型列表
     */
    @ApiOperation("查询事件计划类型列表")
    @PreAuthorize("@ss.hasPermi('module:eventType:list')")
    @GetMapping("/list")
    public TableDataInfo<EventType> list(@Validated EventType eventType) {
        QueryWrapper<EventType> qw = new QueryWrapper<>();
		qw.eq("state",1);
        TableDataInfo<EventType> td = PageUtils.buildDataInfo(eventTypeService.page(PageUtils.buildPage(),qw));
        List<EventType> list = td.getRows();
        return td;
    }

    /**
     * 导出事件计划类型列表
     */
    @ApiOperation("导出事件计划类型列表")
    @PreAuthorize("@ss.hasPermi('module:eventType:export')")
    @Log(title = "事件计划类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EventType> export(@Validated EventType eventType) {
        List<EventType> list = eventTypeService.list();
        ExcelUtil<EventType> util = new ExcelUtil<EventType>(EventType.class);
        return util.exportExcel(list, "事件计划类型");
    }

    /**
     * 获取事件计划类型详细信息
     */
    @ApiOperation("获取事件计划类型详细信息")
    @PreAuthorize("@ss.hasPermi('module:eventType:query')")
    @GetMapping("/{id}")
    public AjaxResult<EventType> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Integer id) {
        EventType eventType = eventTypeService.getById(id);
        return AjaxResult.success(eventType);
    }

    /**
     * 新增事件计划类型
     */
    @ApiOperation("新增事件计划类型")
    @PreAuthorize("@ss.hasPermi('module:eventType:add')")
    @Log(title = "事件计划类型", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody EventType eventType) {
        return toAjax(eventTypeService.save(eventType) ? 1 : 0);
    }

    /**
     * 修改事件计划类型
     */
    @ApiOperation("修改事件计划类型")
    @PreAuthorize("@ss.hasPermi('module:eventType:edit')")
    @Log(title = "事件计划类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody EventType eventType) {
        return toAjax(eventTypeService.updateById(eventType) ? 1 : 0);
    }

    /**
     * 删除事件计划类型
     */
    @ApiOperation("删除事件计划类型")
    @PreAuthorize("@ss.hasPermi('module:eventType:remove')")
    @Log(title = "事件计划类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Integer[] ids) {
        return toAjax(eventTypeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
